const fileDao = require('../dao/fileDao');
const _ = require("lodash");
const { deleteFile } = require('../utils/weixin_utils');
module.exports.create = async function(file){
   
    const newContent = await fileDao.create(file);
    
    return newContent;
}
module.exports.update = async function(file){
    
    return await fileDao.update(file);
}
module.exports.updateUrl = async function(id,url){
    return await fileDao.update({id,url});
}
module.exports.updateWriteName = async function(id,writeName){
    return await fileDao.update({id,writeName});
}
module.exports.delete = async function(id){
    let file = await fileDao.findById(id);
    deleteFile("bankpdf/" + file.title);
    // let images = await imageDao.findByContent({content:id});
    // for(let i = 0;i < images.length;i++){
    //     deleteFile("bank/" + images[i].url);
    // }
    // await imageDao.deleteByContent(id);
    // await carouselDao.deleteByContent(id);
    return await fileDao.delete(id);


}
module.exports.findById = async function(id){
    return await fileDao.findById(id);
}
module.exports.findAll = async function(current,pageSize,searchParams,order){
    return await fileDao.findAll(current,pageSize,searchParams,order);
}